package com.example.demo6.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo6.entity.User;
import com.example.demo6.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2022-07-28 12:08:15
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("doLogin")
    public SaResult doLogin(String account, String password) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>();
        queryWrapper.eq(User::getAccount, account);
        User user= userService.getOne(queryWrapper);

        if (user== null) {
            return SaResult.error("登录失败");
        }

        if(user.getPassword().equals(password)){
            StpUtil.login(user.getId());
            return SaResult.error("登录成功");
        }


        return SaResult.ok("登录失败");
    }
}

